from abc import abstractmethod

from sam.util.fileUtil2 import FileUtil


class CommonFilterFileProcess(FileUtil):
    def __init__(self, file_type: str = "csv"):
        super().__init__()
        self.file_type = file_type

    def handle_file(self, file_path: str):
        lines = self.file_read(file_path)
        column = lines[0]
        abandon_lines = [column]
        save_lines = [column]
        for i, line in enumerate(lines):
            if i == 0:
                continue
            if self.is_save(line):
                save_lines.append(line)
            else:
                abandon_lines.append(line)

        if abandon_lines:
            self.file_write_quick(file_path, abandon_lines, prefix="abandon", file_type=self.file_type)
        if save_lines:
            self.file_write_quick(file_path, save_lines, prefix="save", file_type=self.file_type)

    @abstractmethod
    def is_save(self, line: list) -> bool:
        pass
